<?php

/**
 * 
 * @author Mike Taylor (m.j.taylor@leedsmet.ac.uk)
 *
 */
class MarkupTemplateReplacement
{
	/**
	 * Text code to search for when performing a replacement
	 * @var string
	 */
	private $code_;
	
	/**
	 * Text that will replace the code
	 * @var string
	 */
	private $replacement_;
	
	/**
	 * Flag to indicate whether or not HTML content is allowed in the replacement text
	 * @var bool
	 */
	private $allowHtmlReplacement_;
	
	/**
	 * Constructor for this class
	 * @param $code Text code to be replaced
	 * @param $replacement Text that will replace the code
	 * @param $allowHtmlReplacement Flag to indicate whether or not HTML content is allowed in the replacement text
	 */
	function __construct($code = '', $replacement = '', $allowHtmlReplacement = false)
	{
		$this->setCode($code);
		$this->setReplacement($replacement);
		
		if ($allowHtmlReplacement === true)
		{
			$this->enableHtmlReplacement();
		}
		else
		{
			$this->disableHtmlReplacement();
		}
	}
	
	/**
	 * Returns the text code
	 */
	public function getCode()
	{
		return $this->code_;
	}
	
	/**
	 * Sets the text code
	 * @param string $code
	 */
	public function setCode($code)
	{
		if (is_string($code))
		{
			$this->code_ = $code;
		}
		else
		{
			throw new UnexpectedValueException('Code must be a string');
		}
	}
	
	/**
	 * Returns the replacement text
	 */
	public function getReplacement()
	{
		return $this->replacement_;
	}
	
	/**
	 * Sets the replacement text
	 * @param string $replacement
	 */
	public function setReplacement($replacement)
	{
		if (is_string($replacement))
		{
			$this->replacement_ = $replacement;
		}
		else
		{
			throw UnexpectedValueException('Replacement must be a string');
		}
	}
	
	/**
	 * Returns the current value of the allowHtmlReplacement flag
	 */
	public function getAllowHtmlReplacement()
	{
		return $this->allowHtmlReplacement_;
	}
	
	/**
	 * Enables HTML content in the replacement
	 */
	public function enableHtmlReplacement()
	{
		$this->allowHtmlReplacement_ = true;
	}
	
	/**
	 * Disables HTML content in the replacement
	 */
	public function disableHtmlReplacement()
	{
		$this->allowHtmlReplacement_ = false;
	}
}